<?php

namespace Narti\BouncerBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * RoleRepository
 *
 */
class RoleRepository extends EntityRepository
{
    
            
    public function countAll(){
        
        $em = $this->getEntityManager();
        $query = $em->createQuery("select count(s.id) from NartiBouncerBundle:Role s");
        $count = $query->getSingleScalarResult();
        return $count;
    }
    
    public function findPage($rowsPage, $rowStart, $sortname, $sortorder){
        
        if(!$sortname) $sortname ='createdAt';
        if(!$sortorder) $sortorder ='desc';
                
        $em = $this->getEntityManager();        
        return $em->createQueryBuilder()
               ->select('s.id', 's.name', 's.createdAt')  
               ->from('NartiBouncerBundle:Role', 's') 
               ->orderBy('s.' . $sortname, $sortorder)  
               ->setMaxResults($rowsPage)
               ->setFirstResult($rowStart)
               ->getQuery()
               ->execute();        
    }
}